﻿#ifndef TRANSPORT_CTRL_LOGIC_H
#define TRANSPORT_CTRL_LOGIC_H
#define MyAbs(x)	(((x)>=0)?(x):(-x))
typedef struct
{
	union
	{
		UINT8 Bytes[1];
		struct
		{
			UINT8 fRelayFeedBack:1;
			UINT8 fWaterTemp:1;
			UINT8 fSafeEdge:1;	
			UINT8 fOilPressure:1;
			UINT8 Byte6_NC:4;
		}bit;
	}unDigitalInput;
	union 
	{
		UINT8 Bytes[6];
		struct
		{
			UINT16 u16TempSensor;	  //2
			UINT16 u16TempSensorP_FBK;//2
			UINT16 u16PumpRpm;			  //2
		}bit;
	}unAnalogInput;
}structTransportInput;
typedef struct
{
	union
	{
		UINT8 Bytes[2];
		struct
		{
			UINT8 fLeftOutValve:1;
			UINT8 fChargeRelay:1;
			UINT8 fStartRelay:1;
			UINT8 fStopHoldCtrl:1;
			UINT8 fWaterPumpRelay:1;
			UINT8 fOilPumpCtrl:1;
			UINT8 fPreHeatCtrl:1;
			UINT8 fHorn:1;
			
			UINT8 fLeftInValve:1;
			UINT8 fRightOutValve:1;
			UINT8 fMotionBeep:1;
			UINT8 fRightInValve:1;
			UINT8 fLampCtrl:1;
			UINT8 Byte1NC:3;
		}bit;
	}unDigitalOutput;
	union
	{
		UINT8 Bytes[1];
		struct
		{
			UINT8 u8TempSeneorP;
			
		}bit;
	}unAnalogOutput;
}structTransportOutput;
extern structTransportInput stTransportInput;
extern structTransportOutput stTransportOutput;
extern void vPorcCtrlLogic(void);//1ms
extern void vInitStreerSlope(void);

///////////////////////////////////////////////////////
//斜坡
#define SpeedParaRato						(10)//
typedef struct
{
	INT8 s8OutValue;
	INT16 s16OutValue_X10;//跟随输出值*10
	UINT16 u16StartSlope;
	UINT16 u16StopSlope;
}tSlope;//泵电机斜率处理
extern tSlope stStreerSlope;
extern void vSlope(tSlope *pSlope,INT8 s8Ref,UINT8 u8Cmd);
extern UINT16 vSlope_ms_to_Deta(UINT16 u16Slope_ms_X10,UINT16 u16SpeedPercent,UINT8 u8SlopeCallCycle);
//角度积分
#define MaxStreerAngleX1000	(60000)
#define MinStreerAngleX1000	(-60000)

typedef struct
{
	INT32 Angle_X1000;
	INT16 Angle_X10;
}structStreerAngle;
extern structStreerAngle stStreerAngle;
extern void vProcStreerAngle(structStreerAngle *pStreerAngle,INT8 s8Speed,UINT8 u8Cmd);
extern void vInitStreerAngle(void);
//////////////////////////////////
extern void vProcAngleCaculate(void);
extern void vProcStreer(void);//20ms//角度计算5ms

/*
	转向控制
*/
#define ProcStreerCycleTime	(20)
#define ReturnToZeroTime	(10000/ProcStreerCycleTime)//10s 500
#define ReturnToZeroTimeMin	(5000/ProcStreerCycleTime)//10s 500
typedef enum
{
	WalkModeIdle=0,
	WalkModeFrontStreer,
	WalkModeRearStreer,
	WalkModeFrontRearStreer,
	WalkModeParallelogram,
	WalkModeHorizontal,
	WalkModeRotation,
	WalkModeErr,
}enumWalkMode;
typedef struct
{
	enumWalkMode enWalkMode;
	enumWalkMode enWalkModeLast;
	UINT16 u16StateInCnt;
	float SpeedPerFrontLeft;
	float SpeedPerFrontRight;
	float SpeedPerRearLeft;
	float SpeedPerRearRight;
	float TotalTheta;//内圈轮给定角度
	float Theta2;//外圈轮给定角度
	INT16 s16AngleFrontLeft;
	INT16 s16AngleFrontRight;
	INT16 s16AngleRearLeft;
	INT16 s16AngleRearRight;
}structMovementCtrl;
extern structMovementCtrl stMovementCtrl;
/*行走*/
typedef struct
{
	INT16 s16FrontLeftSpeed;
	INT16 s16FrontRightSpeed;
	INT16 s16RearLeftSpeed;
	INT16 s16RearRightSpeed;
}structSpeedCtrl;
extern structSpeedCtrl stSpeedCtrl;
extern tSlope stWalkSlope;
extern void vProcWalk(void);


#endif
